package org.farng.mp3;

/**
 * This class represents parts of tags. It contains methods that they all use
 * use. ID3v2 tags have frames. Lyrics3 tags have fields. ID3v1 tags do not
 * have parts. It also contains thier header while the body contains the
 * actual fragments.
 *
 * @author Eric Farng
 * @version $Revision: 1.3 $
 */
public abstract class AbstractMP3Fragment extends AbstractMP3FileItem {
    /** actual data this fragment holds */
    protected AbstractMP3FragmentBody body;

    public AbstractMP3Fragment() {}

    public AbstractMP3Fragment(AbstractMP3Fragment copyObject) {
        super(copyObject);
        this.body = (AbstractMP3FragmentBody) TagUtility.copyObject(copyObject.body);
    }

    /**
     * Sets the body object for this fragment. The body object contains the
     * actual information for the fragment.
     *
     * @param body the body object
     */
    public void setBody(AbstractMP3FragmentBody body) {
        this.body = body;
    }

    /**
     * Returns the body object for this fragment. The body object contains the
     * actual information for the fragment.
     *
     * @return the body object
     */
    public AbstractMP3FragmentBody getBody() {
        return this.body;
    }

    /**
     * Returns true if this object and it's body is a subset of the argument.
     * This object is a subset if the argument is the same class.
     *
     * @param obj object to determine if subset of
     *
     * @return true if this object and it's body is a subset of the argument.
     */
    public boolean isSubsetOf(Object obj) {
        if ((obj instanceof AbstractMP3Fragment) == false) {
            return false;
        }

        if (obj == null) {
            return false;
        }

        if ((body == null) && (((AbstractMP3Fragment) obj).body == null)) {
            return true;
        }

        if ((body == null) || (((AbstractMP3Fragment) obj).body == null)) {
            return false;
        }

        if (body.isSubsetOf(((AbstractMP3Fragment) obj).body) == false) {
            return false;
        }

        return super.isSubsetOf(obj);
    }

    /**
     * Returns true if this object and its body equals the argument and its
     * body. this object is equal if and only if they are the same class and
     * have the same <code>getIdentifier</code> id string.
     *
     * @param obj object to determine equality of
     *
     * @return true if this object and its body equals the argument and its
     *         body.
     */
    public boolean equals(Object obj) {
        if ((obj instanceof AbstractMP3Fragment) == false) {
            return false;
        }

        AbstractMP3Fragment object = (AbstractMP3Fragment) obj;

        if (this.getIdentifier().equals(object.getIdentifier()) == false) {
            return false;
        }

        if (this.body.equals(object.body) == false) {
            return false;
        }

        return super.equals(obj);
    }
}